package com.wlyuan.open.scanner.domain.user;

import com.wlyuan.open.scanner.utils.RoleIdsUtils;
import lombok.extern.slf4j.Slf4j;

import java.util.Collections;
import java.util.List;
import java.util.Optional;

/**
 * @author lijing
 * @description
 */
@Slf4j
public class MappingUserRole {

    /**
     * 角色id转换
     *
     * @param roles
     * @return
     */
    public List<Long> createRoleIds(Long roles) {
        try {
            return Optional.ofNullable(roles).map(x -> RoleIdsUtils.getRoleIdLongList(x.intValue())).orElseGet(() -> Collections.emptyList());
        } catch (Exception e) {
            logger.error("roleId:{}", roles);
            e.printStackTrace();
            return Collections.emptyList();
        }
    }
}
